package com.example.test;

import java.util.Stack;

public class LinkList {
    class Node{
        private int data;
        private Node next;

        public Node(int data) {
            this.data = data;
        }

        public int getData() {
            return data;
        }

        public void setData(int data) {
            this.data = data;
        }

        public Node getNext() {
            return next;
        }

        public void setNext(Node next) {
            this.next = next;
        }
    }
    public Node head;

    public void createLinkList(){
        Node pNew;
        Node pTail=new Node(0);
        head=pTail;
        for (int i=1;i<6;i++){
            pNew=new Node(i);
            pTail.setNext(pNew);
            pTail=pNew;
        }
        pTail.setNext(null);
    }

    public void reverseLinkList(){
        Stack<Node> stack=new Stack<>();
        Node node = head.getNext();
        while (node!=null){
            stack.push(node);
            node=node.getNext();
        }
        while(stack.size()>0){
            Node pop = stack.pop();
            System.out.println(pop.getData());
        }
    }

    public static void main(String[] args) {
        LinkList linkList=new LinkList();
        linkList.createLinkList();
        linkList.reverseLinkList();
    }
}
